﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.ClassPlan
{
    public partial class ProjectCoursePreview : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("KCXYM");
            strPageUserType.Add("mana");

            if (Request.QueryString["ID"] == null)
            {
                Common.JShelper.JSAlert(Page, "err", "参数错误!");
                return;
            }

            int CourseID = 0;
            if (int.TryParse(Request.QueryString["ID"], out CourseID)) 
            {

            }
            if (!IsPostBack)
            {
                DataBinds(CourseID);
                GridViewBind(CourseID);
                tbID.Value = CourseID.ToString();
            }
        }

        protected void DataBinds(int CourseID)
        {
            LabMS.BLL.Course Course = new LabMS.BLL.Course();
            LabMS.Model.Course model = new LabMS.Model.Course();
            model = Course.GetModel(CourseID);
            lb_CourseCode.Text = model.Course_Code;
            lb_CourseName.Text = model.Course_Name;
            lb_CourseType.Text = model.CourseType;
            lb_EnglishName.Text = model.EnglishName;
        }

        protected void GridViewBind(int CourseID)
        {
            LabMS.BLL.CourseAndProject courseproject = new LabMS.BLL.CourseAndProject();
            List<LabMS.Model.CourseAndProject> courseprojectlist = new List<LabMS.Model.CourseAndProject>();

            string strWhere1 = " CourseID=" + CourseID;
            courseprojectlist = courseproject.GetModelList(strWhere1);

            string strWhere2 = "";
            
            foreach (LabMS.Model.CourseAndProject cp in courseprojectlist)
            {
                if (cp.ProjectID != null)
                {
                    if (strWhere2.Equals(""))
                    {
                        strWhere2 += " Project.ID=" + cp.ProjectID;
                    }
                    else
                    {
                        strWhere2 += " or Project.ID=" + cp.ProjectID;
                    }
                }
            }
            if (strWhere2 == "") 
            {
                strWhere2 = "1<>1";
            }

            ExtendBLL.ProjectAndOther project = new ExtendBLL.ProjectAndOther();
            List<ExtendModule.ProjectAndOther> projectlist = new List<ExtendModule.ProjectAndOther>();

            projectlist = project.GetModelList2(strWhere2);
            gvProjectList.DataSource = projectlist;
            gvProjectList.DataBind();
        }
    }
}
